package com.youtills.core.logging;

import com.youtills.core.lang.StringUtil;
import org.apache.log4j.Level;

/**
 * Created by IntelliJ IDEA.
 * User: ravi
 * Date: 6/16/12
 * Time: 10:45 PM
 * To change this template use File | Settings | File Templates.
 */
public final class Logger {

    private final org.apache.log4j.Logger logger;

    private Logger(String name) {
        logger = org.apache.log4j.Logger.getLogger(name);
    }

    public static Logger getLogger(String name){
        return new Logger(name);
    }

    public static Logger getLogger(Class clazz){
        return getLogger(clazz.getName());
    }



    public final void error(Exception e, Object... message) {
        if(logger.isEnabledFor(Level.ERROR)){
            logger.error(message, e);
        }
    }

    public final void error(Object... message){
        error(null, message);
    }

    private String messageParts(Object[] messageParts){
        if(messageParts != null){

            StringBuilder message = new StringBuilder();
            for(Object part : messageParts){
                message.append(StringUtil.toString(part));
            }
            return message.toString();
        }
        return null;
    }

    public final void trace(Exception e, Object... message) {
        if(logger.isEnabledFor(Level.TRACE)){
            logger.trace(message, e);
        }
    }

    public final void trace(Object... message){
        error(null, message);
    }
}
